package com.tengju.motivation.domain.shared;

import org.springframework.cglib.beans.BeanMap;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: 大木
 * @date: 2021/12/1 10:24 下午
 */
public class BeanConvertUtil {

    /**
     * 将对象装换为map   =>  {k1=v1, k2=v2, ...}
     *
     * @param bean 对象
     * @return {@link Map}<{@link String}, {@link Object}>
     */
    public static <T> Map<String, Object> beanToMap(T bean) {
        Map<String, Object> map = new HashMap<>();
        if (bean != null) {
            BeanMap beanMap = BeanMap.create(bean);
            for (Object key : beanMap.keySet()) {
                map.put(key + "", beanMap.get(key));
            }
        }
        return map;
    }

}
